<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>19.1.11. email.errors: Exception and Defect classes &mdash; Python 3.4.3 documentation</title>
    
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '3.4.3',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python 3.4.3 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python 3.4.3 documentation" href="../index.html" />
    <link rel="up" title="19.1. email — An email and MIME handling package" href="email.html" />
    <link rel="next" title="19.1.12. email.utils: Miscellaneous utilities" href="email.util.html" />
    <link rel="prev" title="19.1.10. email.encoders: Encoders" href="email.encoders.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    <script type="text/javascript" src="../_static/version_switch.js"></script>
    
 

  </head>
  <body>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="email.util.html" title="19.1.12. email.utils: Miscellaneous utilities"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="email.encoders.html" title="19.1.10. email.encoders: Encoders"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="netdata.html" >19. Internet Data Handling</a> &raquo;</li>
          <li><a href="email.html" accesskey="U">19.1. <tt class="docutils literal"><span class="pre">email</span></tt> &#8212; An email and MIME handling package</a> &raquo;</li> 
      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-email.errors">
<span id="email-errors-exception-and-defect-classes"></span><h1>19.1.11. <a class="reference internal" href="#module-email.errors" title="email.errors: The exception classes used by the email package."><tt class="xref py py-mod docutils literal"><span class="pre">email.errors</span></tt></a>: Exception and Defect classes<a class="headerlink" href="#module-email.errors" title="Permalink to this headline">¶</a></h1>
<p>The following exception classes are defined in the <a class="reference internal" href="#module-email.errors" title="email.errors: The exception classes used by the email package."><tt class="xref py py-mod docutils literal"><span class="pre">email.errors</span></tt></a> module:</p>
<dl class="exception">
<dt id="email.errors.MessageError">
<em class="property">exception </em><tt class="descclassname">email.errors.</tt><tt class="descname">MessageError</tt><a class="headerlink" href="#email.errors.MessageError" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the base class for all exceptions that the <a class="reference internal" href="email.html#module-email" title="email: Package supporting the parsing, manipulating, and generating email messages, including MIME documents."><tt class="xref py py-mod docutils literal"><span class="pre">email</span></tt></a> package can
raise.  It is derived from the standard <a class="reference internal" href="exceptions.html#Exception" title="Exception"><tt class="xref py py-exc docutils literal"><span class="pre">Exception</span></tt></a> class and defines no
additional methods.</p>
</dd></dl>

<dl class="exception">
<dt id="email.errors.MessageParseError">
<em class="property">exception </em><tt class="descclassname">email.errors.</tt><tt class="descname">MessageParseError</tt><a class="headerlink" href="#email.errors.MessageParseError" title="Permalink to this definition">¶</a></dt>
<dd><p>This is the base class for exceptions raised by the <a class="reference internal" href="email.parser.html#email.parser.Parser" title="email.parser.Parser"><tt class="xref py py-class docutils literal"><span class="pre">Parser</span></tt></a>
class.  It is derived from <a class="reference internal" href="#email.errors.MessageError" title="email.errors.MessageError"><tt class="xref py py-exc docutils literal"><span class="pre">MessageError</span></tt></a>.</p>
</dd></dl>

<dl class="exception">
<dt id="email.errors.HeaderParseError">
<em class="property">exception </em><tt class="descclassname">email.errors.</tt><tt class="descname">HeaderParseError</tt><a class="headerlink" href="#email.errors.HeaderParseError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised under some error conditions when parsing the <span class="target" id="index-0"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a> headers of a
message, this class is derived from <a class="reference internal" href="#email.errors.MessageParseError" title="email.errors.MessageParseError"><tt class="xref py py-exc docutils literal"><span class="pre">MessageParseError</span></tt></a>. It can be raised
from the <a class="reference internal" href="email.parser.html#email.parser.Parser.parse" title="email.parser.Parser.parse"><tt class="xref py py-meth docutils literal"><span class="pre">Parser.parse</span></tt></a> or
<a class="reference internal" href="email.parser.html#email.parser.Parser.parsestr" title="email.parser.Parser.parsestr"><tt class="xref py py-meth docutils literal"><span class="pre">Parser.parsestr</span></tt></a> methods.</p>
<p>Situations where it can be raised include finding an envelope header after the
first <span class="target" id="index-1"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a> header of the message, finding a continuation line before the
first <span class="target" id="index-2"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a> header is found, or finding a line in the headers which is
neither a header or a continuation line.</p>
</dd></dl>

<dl class="exception">
<dt id="email.errors.BoundaryError">
<em class="property">exception </em><tt class="descclassname">email.errors.</tt><tt class="descname">BoundaryError</tt><a class="headerlink" href="#email.errors.BoundaryError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised under some error conditions when parsing the <span class="target" id="index-3"></span><a class="rfc reference external" href="http://tools.ietf.org/html/rfc2822.html"><strong>RFC 2822</strong></a> headers of a
message, this class is derived from <a class="reference internal" href="#email.errors.MessageParseError" title="email.errors.MessageParseError"><tt class="xref py py-exc docutils literal"><span class="pre">MessageParseError</span></tt></a>. It can be raised
from the <a class="reference internal" href="email.parser.html#email.parser.Parser.parse" title="email.parser.Parser.parse"><tt class="xref py py-meth docutils literal"><span class="pre">Parser.parse</span></tt></a> or
<a class="reference internal" href="email.parser.html#email.parser.Parser.parsestr" title="email.parser.Parser.parsestr"><tt class="xref py py-meth docutils literal"><span class="pre">Parser.parsestr</span></tt></a> methods.</p>
<p>Situations where it can be raised include not being able to find the starting or
terminating boundary in a <em class="mimetype">multipart/*</em> message when strict parsing
is used.</p>
</dd></dl>

<dl class="exception">
<dt id="email.errors.MultipartConversionError">
<em class="property">exception </em><tt class="descclassname">email.errors.</tt><tt class="descname">MultipartConversionError</tt><a class="headerlink" href="#email.errors.MultipartConversionError" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised when a payload is added to a <a class="reference internal" href="email.message.html#email.message.Message" title="email.message.Message"><tt class="xref py py-class docutils literal"><span class="pre">Message</span></tt></a> object
using <tt class="xref py py-meth docutils literal"><span class="pre">add_payload()</span></tt>, but the payload is already a scalar and the
message&#8217;s <em class="mailheader">Content-Type</em> main type is not either
<em class="mimetype">multipart</em> or missing.  <a class="reference internal" href="#email.errors.MultipartConversionError" title="email.errors.MultipartConversionError"><tt class="xref py py-exc docutils literal"><span class="pre">MultipartConversionError</span></tt></a> multiply
inherits from <a class="reference internal" href="#email.errors.MessageError" title="email.errors.MessageError"><tt class="xref py py-exc docutils literal"><span class="pre">MessageError</span></tt></a> and the built-in <a class="reference internal" href="exceptions.html#TypeError" title="TypeError"><tt class="xref py py-exc docutils literal"><span class="pre">TypeError</span></tt></a>.</p>
<p>Since <tt class="xref py py-meth docutils literal"><span class="pre">Message.add_payload()</span></tt> is deprecated, this exception is rarely
raised in practice.  However the exception may also be raised if the
<a class="reference internal" href="email.message.html#email.message.Message.attach" title="email.message.Message.attach"><tt class="xref py py-meth docutils literal"><span class="pre">attach()</span></tt></a>
method is called on an instance of a class derived from
<a class="reference internal" href="email.mime.html#email.mime.nonmultipart.MIMENonMultipart" title="email.mime.nonmultipart.MIMENonMultipart"><tt class="xref py py-class docutils literal"><span class="pre">MIMENonMultipart</span></tt></a> (e.g.
<a class="reference internal" href="email.mime.html#email.mime.image.MIMEImage" title="email.mime.image.MIMEImage"><tt class="xref py py-class docutils literal"><span class="pre">MIMEImage</span></tt></a>).</p>
</dd></dl>

<p>Here&#8217;s the list of the defects that the <a class="reference internal" href="email.parser.html#email.parser.FeedParser" title="email.parser.FeedParser"><tt class="xref py py-class docutils literal"><span class="pre">FeedParser</span></tt></a>
can find while parsing messages.  Note that the defects are added to the message
where the problem was found, so for example, if a message nested inside a
<em class="mimetype">multipart/alternative</em> had a malformed header, that nested message
object would have a defect, but the containing messages would not.</p>
<p>All defect classes are subclassed from <tt class="xref py py-class docutils literal"><span class="pre">email.errors.MessageDefect</span></tt>, but
this class is <em>not</em> an exception!</p>
<ul>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">NoBoundaryInMultipartDefect</span></tt> &#8211; A message claimed to be a multipart,
but had no <em class="mimetype">boundary</em> parameter.</p>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">StartBoundaryNotFoundDefect</span></tt> &#8211; The start boundary claimed in the
<em class="mailheader">Content-Type</em> header was never found.</p>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">CloseBoundaryNotFoundDefect</span></tt> &#8211; A start boundary was found, but
no corresponding close boundary was ever found.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">FirstHeaderLineIsContinuationDefect</span></tt> &#8211; The message had a continuation
line as its first header line.</p>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">MisplacedEnvelopeHeaderDefect</span></tt> - A &#8220;Unix From&#8221; header was found in the
middle of a header block.</p>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">MissingHeaderBodySeparatorDefect</span></tt> - A line was found while parsing
headers that had no leading white space but contained no &#8216;:&#8217;.  Parsing
continues assuming that the line represents the first line of the body.</p>
<div class="versionadded">
<p><span class="versionmodified">New in version 3.3.</span></p>
</div>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">MalformedHeaderDefect</span></tt> &#8211; A header was found that was missing a colon,
or was otherwise malformed.</p>
<div class="deprecated">
<p><span class="versionmodified">Deprecated since version 3.3: </span>This defect has not been used for several Python versions.</p>
</div>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">MultipartInvariantViolationDefect</span></tt> &#8211; A message claimed to be a
<em class="mimetype">multipart</em>, but no subparts were found.  Note that when a message
has this defect, its <a class="reference internal" href="email.message.html#email.message.Message.is_multipart" title="email.message.Message.is_multipart"><tt class="xref py py-meth docutils literal"><span class="pre">is_multipart()</span></tt></a> method may
return false even though its content type claims to be <em class="mimetype">multipart</em>.</p>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">InvalidBase64PaddingDefect</span></tt> &#8211; When decoding a block of base64
enocded bytes, the padding was not correct.  Enough padding is added to
perform the decode, but the resulting decoded bytes may be invalid.</p>
</li>
<li><p class="first"><tt class="xref py py-class docutils literal"><span class="pre">InvalidBase64CharactersDefect</span></tt> &#8211; When decoding a block of base64
enocded bytes, characters outside the base64 alphebet were encountered.
The characters are ignored, but the resulting decoded bytes may be invalid.</p>
</li>
</ul>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h4>Previous topic</h4>
  <p class="topless"><a href="email.encoders.html"
                        title="previous chapter">19.1.10. <tt class="docutils literal"><span class="pre">email.encoders</span></tt>: Encoders</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="email.util.html"
                        title="next chapter">19.1.12. <tt class="docutils literal"><span class="pre">email.utils</span></tt>: Miscellaneous utilities</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/email.errors.txt"
         rel="nofollow">Show Source</a></li>
</ul>

<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="email.util.html" title="19.1.12. email.utils: Miscellaneous utilities"
             >next</a> |</li>
        <li class="right" >
          <a href="email.encoders.html" title="19.1.10. email.encoders: Encoders"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &raquo;</li>
        <li>
          <span class="version_switcher_placeholder">3.4.3</span>
          <a href="../index.html">Documentation</a> &raquo;
        </li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="netdata.html" >19. Internet Data Handling</a> &raquo;</li>
          <li><a href="email.html" >19.1. <tt class="docutils literal"><span class="pre">email</span></tt> &#8212; An email and MIME handling package</a> &raquo;</li> 
      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2015, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.
    <a href="https://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Feb 26, 2015.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.2.3.
    </div>

  </body>
</html>